﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ConstellationShow.Function.DocData;
using Microsoft.Phone.Tasks;

namespace ConstellationShow
{
    public partial class Doc : MyPage
    {
        int id;
        string InitIndex;
        string texts = "";
        public Doc()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Doc_Loaded);
        }

        void Doc_Loaded(object sender, RoutedEventArgs e)
        {
            InitIndex = NavigationContext.QueryString["index"];
            id = Convert.ToInt32(NavigationContext.QueryString["id"]);
            GetData(InitIndex);
            GetData("传说"); GetData("起源"); GetData("男生"); //初始化所有
            GetData("女生"); GetData("爱情"); GetData("性格");
            if (InitIndex == "传说") piv.SelectedIndex = 0;
            else if (InitIndex == "起源") piv.SelectedIndex = 1;
            else if (InitIndex == "男生") piv.SelectedIndex = 2;
            else if (InitIndex == "女生") piv.SelectedIndex = 3;
            else if (InitIndex == "爱情") piv.SelectedIndex = 4;
            else if (InitIndex == "性格") piv.SelectedIndex = 5;

            img1.Content = img2.Content = img3.Content = img4.Content = img5.Content
                = img6.Content = Info.ConvStr(id.ToString());
            img1.CommandParameter = img2.CommandParameter = img3.CommandParameter
                = img4.CommandParameter = img5.CommandParameter
                = img6.Content = Com.ConsMonth(id);
            img1.Tag = img2.Tag = img3.Tag = img4.Tag = img5.Tag
                = img6.Tag = "/Images/" + Com.ConsImg(id);
        }

        void GetData(string index)
        {
            string text = "";
            if (index == "传说")
            {
                if (id == 0) text = Legeng.getBaiYang();
                if (id == 1) text = Legeng.getJinNiu();
                if (id == 2) text = Legeng.getShuangZi();
                if (id == 3) text = Legeng.getJuXie();
                if (id == 4) text = Legeng.getShiZi();
                if (id == 5) text = Legeng.getChuNv();
                if (id == 6) text = Legeng.getTianCheng();
                if (id == 7) text = Legeng.getTianXie();
                if (id == 8) text = Legeng.getSheShou();
                if (id == 9) text = Legeng.getMoJie();
                if (id == 10) text = Legeng.getShuiPing();
                if (id == 11) text = Legeng.getShuangYu();
                SetUIData(text, txt1, list1);
            }
            else if (index == "起源")
            {
                if (id == 0) text = Origin.getBaiYang();
                if (id == 1) text = Origin.getJinNiu();
                if (id == 2) text = Origin.getShuangZi();
                if (id == 3) text = Origin.getJuXie();
                if (id == 4) text = Origin.getShiZi();
                if (id == 5) text = Origin.getChuNv();
                if (id == 6) text = Origin.getTianCheng();
                if (id == 7) text = Origin.getTianXie();
                if (id == 8) text = Origin.getSheShou();
                if (id == 9) text = Origin.getMoJie();
                if (id == 10) text = Origin.getShuiPing();
                if (id == 11) text = Origin.getShuangYu();
                SetUIData(text, txt2, list2);
            }
            else if (index == "男生")
            {
                if (id == 0) text = Boy.getBaiYang();
                if (id == 1) text = Boy.getJinNiu();
                if (id == 2) text = Boy.getShuangZi();
                if (id == 3) text = Boy.getJuXie();
                if (id == 4) text = Boy.getShiZi();
                if (id == 5) text = Boy.getChuNv();
                if (id == 6) text = Boy.getTianCheng();
                if (id == 7) text = Boy.getTianXie();
                if (id == 8) text = Boy.getSheShou();
                if (id == 9) text = Boy.getMoJie();
                if (id == 10) text = Boy.getShuiPing();
                if (id == 11) text = Boy.getShuangYu();
                SetUIData(text, txt3, list3);
            }
            else if (index == "女生")
            {
                if (id == 0) text = Girl.getBaiYang();
                if (id == 1) text = Girl.getJinNiu();
                if (id == 2) text = Girl.getShuangZi();
                if (id == 3) text = Girl.getJuXie();
                if (id == 4) text = Girl.getShiZi();
                if (id == 5) text = Girl.getChuNv();
                if (id == 6) text = Girl.getTianCheng();
                if (id == 7) text = Girl.getTianXie();
                if (id == 8) text = Girl.getSheShou();
                if (id == 9) text = Girl.getMoJie();
                if (id == 10) text = Girl.getShuiPing();
                if (id == 11) text = Girl.getShuangYu();
                SetUIData(text, txt4, list4);
            }
            else if (index == "爱情")
            {
                if (id == 0) text = Love.getBaiYang();
                if (id == 1) text = Love.getJinNiu();
                if (id == 2) text = Love.getShuangZi();
                if (id == 3) text = Love.getJuXie();
                if (id == 4) text = Love.getShiZi();
                if (id == 5) text = Love.getChuNv();
                if (id == 6) text = Love.getTianCheng();
                if (id == 7) text = Love.getTianXie();
                if (id == 8) text = Love.getSheShou();
                if (id == 9) text = Love.getMoJie();
                if (id == 10) text = Love.getShuiPing();
                if (id == 11) text = Love.getShuangYu();
                SetUIData(text, txt5, list5);
            }
            else if (index == "性格")
            {
                if (id == 0) text = Character.getBaiYang();
                if (id == 1) text = Character.getJinNiu();
                if (id == 2) text = Character.getShuangZi();
                if (id == 3) text = Character.getJuXie();
                if (id == 4) text = Character.getShiZi();
                if (id == 5) text = Character.getChuNv();
                if (id == 6) text = Character.getTianCheng();
                if (id == 7) text = Character.getTianXie();
                if (id == 8) text = Character.getSheShou();
                if (id == 9) text = Character.getMoJie();
                if (id == 10) text = Character.getShuiPing();
                if (id == 11) text = Character.getShuangYu();
                SetUIData(text, txt6, list6);
            }

        }

        void SetUIData(string text, TextBlock txt, ListBox lst)
        {
            texts = text;
            string text1 = text.Substring(0, 54);
            txt.Text = text1;
            string text2 = text.Replace(text1, "");
            int num = text2.Length / 800;
            for (int i = 0; i <= num; i++)
            {
                int number = 800;
                if (i == num) number = text2.Length % 800;
                string str = text2.Substring(i * 800, number);
                TextBlock t = new TextBlock();
                t.TextWrapping = TextWrapping.Wrap;
                t.VerticalAlignment = VerticalAlignment.Top;
                t.FontSize = 24;
                t.Foreground = new SolidColorBrush(Com.HtmlToColor("#1d1d1d"));
                t.Text = str;
                lst.Items.Add(t);
            }
        }

        private void Click_Share(object sender, EventArgs e)
        {
            Com.Share(Info.ConvStr(id.ToString()) + InitIndex, texts );
        }
    }

}
